/*
 * 学科
 */

import { createAPI } from '@/utils/request'
// 引入moment
import moment from 'moment'


// 学科列表
export const list = data => createAPI('/subjects', 'get', data)
.then(res => ({
  items: res.data.items.map((d, i) => ({
    ...d,
    index: i + 1,
    isFrontDisplay: d.isFrontDisplay === 1 ? '是' : '否',
    addDate: moment(d.addDate).format('YYYY-MM-DD HH:mm:ss'),
  })),
  counts: res.data.counts
}))
.catch(err => err)


// 学科简单列表
export const simple = data => createAPI('/subjects/simple', 'get', data)
.then(res => res.data)
.catch(err => err)

// 学科详情
export const detail = data => createAPI(`/subjects/${data.id}`, 'get', data)

// 学科添加
export const addSubject = data => createAPI('/subjects', 'post', data)
.then(res => res)
.catch(err => err)

// 学科修改
export const updateSubject = data => createAPI(`/subjects/${data.id}`, 'put', data)
.then(res => res)
.catch(err => err)

// 学科删除
export const deleteSubject = data => createAPI(`/subjects/${data.id}`, 'delete', data)
.then(res =>res)
.catch(err => err)
